updating oE flush

flush

include io.e 
namespace io 
public procedure flush(file_number fn) 

forces writing any buffered data to an open file or device.

Parameters:
  1. fn : an integer, the handle to the file or device to close.
Errors:

The target file or device must be open.

Comments:

When you write data to a file, Euphoria normally stores the data in a memory buffer until a large enough chunk of data has accumulated. This large chunk can then be written to disk very efficiently. Sometimes you may want to force, or flush, all data out immediately, even if the memory buffer is not full. To do this you must call flush(fn), where fn is the file number of a file open for writing or appending.

When a file is closed, (see close), all buffered data is flushed out. When a program terminates, all open files are flushed and closed automatically. Use flush when another process may need to see all of the data written so far, but you are not ready to close the file yet. flush is also used in crash routines, where files may not be closed in the cleanest possible way.

Example 1:
f = open("file.log", "w") 
puts(f, "Record#1\n") 
puts(STDOUT, "Press Enter when ready\n") 
 
flush(f)  -- This forces "Record #1" into "file.log" on disk. 
          -- Without this, "file.log" will appear to have 
          -- 0 characters when we stop for keyboard input. 
 
s = gets(0) -- wait for keyboard input 
See Also:

close, crash_routine

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu